/***************************/
//@Author: Adrian "yEnS" Mato Gondelle & Ivan Guardado Castro
//@website: www.yensdesign.com
//@email: whitefang_wolf19@yahoo.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

$(document).ready(function(){
    //==================================================================================================//
    //-------------------------------------- Validate Functions ----------------------------------------//
    //==================================================================================================//
    
    //Validation for Input
    function validateInput(el, el_name, info){
        var el_val      = el.val();
        
        if(el_val == ""){
            info.text("Form " + el_name + " harus diisi!");
			info.addClass("messages alert-danger registration").css('display','block');
			return false;
        }else{
			info.fadeOut();
            return true;
		}
    }
    
    //Validation for Select
    function validateSelect(el, el_name, info){
        var el_val      = el.val();
        
        if(el_val == null){
            info.text("Form " + el_name + " harus diisi!");
			info.addClass("messages alert-danger registration").css('display','block');
			return false;
        }else{
			info.fadeOut();
            return true;
		}
    }
    
    //Validation for Name
    function validateName(el, info){
        var el_length   = el.val().length;
        var el_val      = el.val();
        
        if(el_val == ""){
            info.text("Form nama harus diisi!");
			info.addClass("messages alert-danger registration").css('display','block');
			return false;
        }else if(el_length < 4){
            info.text("Form nama harus lebih dari 4 karakter!");
			info.addClass("messages alert-danger registration").css('display','block');
			return false;
        }else{
			info.fadeOut();
            return true;
		}
	}
    
    //Validation for Email
    function validateEmail(el, info, req){
		var a         = el.val();
		var filter    = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        
        if(a != "" && !filter.test(a)){
            info.text("Inputkan alamat email valid Anda");
			info.addClass("messages alert-danger registration").css('display','block');
			return false;
		}else{
            if(req == 1 && a == ""){
                info.text("Form email harus diisi!");
    			info.addClass("messages alert-danger registration").css('display','block');
    			return false;
            }else{
                info.fadeOut();
                return true;
            }
		}
	}
    
    //Validation for Phone
    function validatePhone(el, info, req){
        var el_length   = el.val().length;
        
        if(el_length > 15){
            info.text("Form Telp/HP maksimal 15 karakter!");
			info.addClass("messages alert-danger registration").css('display','block');
			return false;
        }else{
            if( req == 1 && el.val() == "" ){
                info.text("Form telp harus diisi!");
                info.addClass("messages alert-danger registration").css('display','block');
            }else{
                info.fadeOut();
                return true;   
            }
		}
	}
    
    //Validation for ID
    function validateID(el, info){
        var el_length   = el.val().length;
        
        if(el_length > 16){
            info.text("Form No KTP/SIM/PASSPORT maksimal 16 karakter!");
			info.addClass("messages alert-danger registration").css('display','block');
			return false;
        }else{
			info.fadeOut();
            return true;
		}
	}
    
    //Validation for Password
    function validatePassword(el, info){
        var el_length   = el.val().length;
        var el_val      = el.val();
        
        if(el_val == ""){
            info.text("Form password harus diisi!");
			info.addClass("messages alert-danger registration").css('display','block');
			return false;
        }else if(el_length < 6){
            info.text("Form password minimal harus 6 karakter!");
			info.addClass("messages alert-danger registration").css('display','block');
			return false;
        }else{
			info.fadeOut();
            return true;
		}
    }
    
    //Validation for Confirmation Password
    function validateCpassword(el, pass, info){
        var a   = pass.val();
        var b   = el.val();
        
        if(b == ""){
            info.text("Form konfirmasi password harus diisi!");
			info.addClass("messages alert-danger registration").css('display','block');
			return false;
        }else if(a != b){
            info.text("Konfirmasi password tidak sesuai dengan password yang anda masukkan");
			info.addClass("messages alert-danger registration").css('display','block');
			return false;
        }else{
			info.fadeOut();
            return true;
		}
    }
    
    //Validation for Security Answer
    function validateSecurity(el, num1, num2, info){
        var a   = num1.val();
        var b   = num2.val();
        var c   = el.val();
        var sum = parseInt(a) + parseInt(b);
        
        if(c == ""){
            info.text("Form pertanyaan keamanan harus diisi!");
			info.addClass("messages alert-danger registration").css('display','block');
			return false;
        }else if(c != sum){
            info.text("Jawaban pertanyaan keamanan salah!");
			info.addClass("messages alert-danger registration").css('display','block');
			return false;
        }else{
			info.fadeOut();
            return true;
		}
    }
    //==================================================================================================//
    
    //==================================================================================================//
    //-------------------------------------- Register Validation ---------------------------------------//
    //==================================================================================================//
    
    //Form Declaration
    var reg_form            = $("#register-form");
    
    //Global Vars
    var reg_nama            = $("#reg_nama");
    var reg_namaInfo        = $("#reg_nama_info");
    var reg_email           = $('#reg_email');
    var reg_emailInfo       = $("#reg_email_info");
    var reg_password        = $("#reg_password");
    var reg_passwordInfo    = $("#reg_password_info");
    var reg_cpassword       = $("#reg_cpassword");
    var reg_cpasswordInfo   = $("#reg_cpassword_info");
    var reg_security        = $("#reg_security");
    var reg_securityInfo    = $("#reg_security_info");
    var reg_num1            = $("#reg_qwe");
    var reg_num2            = $("#reg_ewq");
    
    //Bind Input
    reg_nama.bind('keyup blur', function(){ validateName(reg_nama, reg_namaInfo) });
    reg_email.bind('keyup blur', function(){ validateEmail(reg_email, reg_emailInfo, 1) });
    reg_password.bind('keyup blur', function(){ validatePassword(reg_password, reg_passwordInfo) });
    reg_cpassword.bind('keyup blur', function(){ validateCpassword(reg_cpassword, reg_password, reg_cpasswordInfo) });
    reg_security.bind('keyup change click', function(){ validateSecurity(reg_security, reg_num1, reg_num2, reg_securityInfo) });
    
    //On Submitting
	$("#button-register").click(function (e) {
        e.preventDefault();
        
		if( validateName(reg_nama, reg_namaInfo) & 
            validateEmail(reg_email, reg_emailInfo, 1) & 
            validatePassword(reg_password, reg_passwordInfo) & 
            validateCpassword(reg_cpassword, reg_password, reg_cpasswordInfo) & 
            validateSecurity(reg_security, reg_num1, reg_num2, reg_securityInfo) ){
                
            var url = 'member/register';
            
            $.ajax({
    			type : "POST",
    			url  : url,
    			data : {
                    'name'      : reg_nama.val(),
                    'email'     : reg_email.val(),
                    'password'  : reg_password.val(),
                },
                beforeSend: function(){
                    $("div#mask").fadeIn();
                },
    			success: function(response) {                 
                    $("div#messages").removeClass("alert-success").addClass("alert-danger");
                    
                    if(response == '3')         { $("div#messages").fadeIn().html("<strong>ERROR: </strong>Register tidak berhasil!").delay(5000).fadeOut(); }
                    else if(response == '0')    { $("div#messages").fadeIn().html("<strong>ERROR: </strong>Email sudah terdaftar!").delay(5000).fadeOut(); }
                    else if(response == '2')    { $("div#messages").fadeIn().html("<strong>ERROR: </strong>Data yang anda masukkan error").delay(5000).fadeOut(); }
                    else                        { $(location).attr('href',response); }
                    
                    clearformall(reg_form);
                    $("div#mask").fadeOut();
                    generate_captcha();
    			}
    		});
        }else{
            return false;
        }
        return false;
	});
    //==================================================================================================//
    
    
    //==================================================================================================//
    //--------------------------------------- Login Validation -----------------------------------------//
    //==================================================================================================//
    
    //Form Declaration
    var log_form            = $("#login-form");
    
    //Global Vars
    var log_email           = $('#log_email');
    var log_emailInfo       = $("#log_email_info");
    var log_password        = $("#log_password");
    var log_passwordInfo    = $("#log_password_info");
    var log_security        = $("#log_security");
    var log_securityInfo    = $("#log_security_info");
    var log_num1            = $("#log_qwe");
    var log_num2            = $("#log_ewq");
    
    //Bind Input
    log_email.bind('keyup blur', function(){ validateEmail(log_email, log_emailInfo, 1) });
    log_password.bind('keyup blur', function(){ validatePassword(log_password, log_passwordInfo) });
    log_security.bind('keyup change click', function(){ validateSecurity(log_security, log_num1, log_num2, log_securityInfo) });
    
    //On Submitting
	$("#button-login").click(function (e) {
        e.preventDefault();
        
		if( validateEmail(log_email, log_emailInfo, 1) & 
            validatePassword(log_password, log_passwordInfo) & 
            validateSecurity(log_security, log_num1, log_num2, log_securityInfo) ){
                
            var url = 'member/login';

            $.ajax({
    			type : "POST",
    			url  : url,
    			data : {
                    'email'     : log_email.val(),
                    'password'  : log_password.val(),
                },
                beforeSend: function(){
                    $("div#mask").fadeIn();
                },
    			success: function(response) {
                    if(response == 'Failed') { 
                        $("div#messages").fadeIn().html("<strong>ERROR: </strong>Login tidak berhasil! Cek kembali email dan password Anda.").delay(5000).fadeOut(); 
                        $("div#mask").fadeOut();
                        clearformall(log_form);
                    }else if(response == 'Deleted'){
                        $("div#messages").fadeIn().html("<strong>ERROR: </strong>User tidak terdaftar!").delay(5000).fadeOut(); 
                        $("div#mask").fadeOut();
                        clearformall(log_form);
                    }else if(response == 'Banned'){
                        $("div#messages").fadeIn().html("<strong>ERROR: </strong>User sudah di banned!").delay(5000).fadeOut(); 
                        $("div#mask").fadeOut();
                        clearformall(log_form);
                    }else if(response == 'Logged'){
                        $("div#messages").fadeIn().html("<strong>ERROR: </strong>User sedang aktif login!").delay(5000).fadeOut(); 
                        $("div#mask").fadeOut();
                        clearformall(log_form);
                    }else{
                        $('html, body').animate({ scrollTop: $("#top").offset().top}, 500);
                        $(location).attr('href',response);
                    }
    			}
    		});
        }else{
            return false;
        }
        return false;
	});
    //==================================================================================================//
    
    
    //==================================================================================================//
    //---------------------------------- Reset Password Validation -------------------------------------//
    //==================================================================================================//
    
    //Form Declaration
    var reset_form          = $("#reset-password-form");
    
    //Global Vars
    var cur_pass            = $('#res_cur_password');
    var cur_passInfo        = $("#res_cur_password_info");
    var new_pass            = $("#res_new_password");
    var new_passInfo        = $("#res_new_password_info");
    var new_cpass           = $("#res_new_cpassword");
    var new_cpassInfo       = $("#res_new_cpassword_info");
    var res_security        = $("#res_security");
    var res_securityInfo    = $("#res_security_info");
    var res_num1            = $("#res_qwe");
    var res_num2            = $("#res_ewq");
    
    //Bind Input
    cur_pass.bind('keyup blur', function(){ validateInput(cur_pass, 'current password', cur_passInfo) });
    new_pass.bind('keyup blur', function(){ validatePassword(new_pass, new_passInfo) });
    new_cpass.bind('keyup blur', function(){ validateCpassword(new_cpass, new_pass, new_cpassInfo) });
    res_security.bind('keyup change click', function(){ validateSecurity(res_security, res_num1, res_num2, res_securityInfo) });
    
    //On Submitting
	$("#button-respass").click(function (e) {
        e.preventDefault();
        
		if( validateInput(cur_pass, 'current password', cur_passInfo) & 
            validatePassword(new_pass, new_passInfo) & 
            validateCpassword(new_cpass, new_pass, new_cpassInfo) & 
            validateSecurity(res_security, res_num1, res_num2, res_securityInfo) ){
                
            var url = $(reset_form).attr('action');
            
            $.ajax({
    			type : "POST",
    			url  : url,
    			data : {
                    'current_pass'      : cur_pass.val(),
                    'new_pass'          : new_pass.val(),
                    'new_passconfirm'   : new_cpass.val(),
                },
                beforeSend: function(){
                    $("div#mask").fadeIn();
                },
    			success: function(response) { 
                    $("div#messages").removeClass("alert-success").addClass("alert-danger");
                    
                    if(response == '3')         { $("div#messages").fadeIn().html("<strong>ERROR: </strong>Konfirmasi password baru tidak sesuai!").delay(5000).fadeOut(); }
                    else if(response == '0')    { $("div#messages").fadeIn().html("<strong>ERROR: </strong>Password lama Anda tidak sesuai!").delay(5000).fadeOut(); }
                    else if(response == '2')    { $("div#messages").fadeIn().html("<strong>ERROR: </strong>Data yang anda masukkan error").delay(5000).fadeOut(); }
                    else                        { $(location).attr('href',response); }
                    
                    clearformall(reset_form);
                    $("div#mask").fadeOut();
                    generate_captcha();
    			}
    		});
        }
        return false;
    });
    
    $('#button-respass-reset').click(function(e) {
        e.preventDefault();
        clearformall(reset_form);
    });
    //==================================================================================================//
    
    
    //==================================================================================================//
    //---------------------------------- Case Reporting as Korban --------------------------------------//
    //==================================================================================================//
    
    //Form Declaration
    var kor_report_form     = $("#korban-report-form");
    
    //Global Vars Korban
    var kor_name            = $("#korban_name");
    var kor_nameInfo        = $("#korban_name_info");
    var kor_tgllahir        = $("#korban_tgllahir");
    var kor_tgllahirInfo    = $("#korban_tgllahir_info");
    var kor_idcard          = $("#korban_idcard");
    var kor_idcardInfo      = $("#korban_idcard_info");
    var kor_statushiv       = $("#korban_statushiv");
    var kor_statushivInfo   = $("#korban_statushiv_info");
    var kor_propinsi        = $("#korban_propinsi");
    var kor_propinsiInfo    = $("#korban_propinsi_info");
    var kor_kota            = $("#korban_kota");
    var kor_kotaInfo        = $("#korban_kota_info");
    var kor_hp              = $("#korban_hp");
    var kor_hpInfo          = $("#korban_hp_info");
    var kor_email           = $("#korban_email");
    var kor_emailInfo       = $("#korban_email_info");
    
    //Global Vars Pelaku
    var pel_name            = $('#pelaku_name');
    var pel_nameInfo        = $("#pelaku_name_info");
    var pel_nick            = $('#pelaku_nick');
    var pel_nickInfo        = $("#pelaku_nick_info");
    var pel_jk              = $('#pelaku_jk');
    var pel_jkInfo          = $("#pelaku_jk_info");
    var pel_noid            = $("#pelaku_noid");
    var pel_noidInfo        = $("#pelaku_noid_info");
    var pel_hub_kat         = $('#pelaku_hub_kat');
    var pel_hub_katInfo     = $("#pelaku_hub_kat_info");
    var pel_hub             = $('#pelaku_hub');
    var pel_hubInfo         = $("#pelaku_hub_info");
    var pel_telp            = $('#pelaku_telp');
    var pel_telpInfo        = $("#pelaku_telp_info");
    var pel_alamat          = $('#pelaku_alamat');
    var pel_alamatInfo      = $("#pelaku_alamat_info");
    var pel_email           = $('#pelaku_email');
    var pel_emailInfo       = $("#pelaku_email_info");
    var pel_jkus            = $('#pelaku_jkus');
    var pel_jkusInfo        = $("#pelaku_jkus_info");
    var pel_warkul          = $('#pelaku_warkul');
    var pel_warkulInfo      = $("#pelaku_warkul_info");
    var pel_tinggi          = $('#pelaku_tinggi');
    var pel_tinggiInfo      = $("#pelaku_tinggi_info");
    var pel_tanda           = $('#pelaku_tanda');
    var pel_tandaInfo       = $("#pelaku_tanda_info");
    var pel_karakter        = $('#pelaku_karakter');
    var pel_karakterInfo    = $("#pelaku_karakter_info");
    var pel_ciwaj           = $('#pelaku_ciwaj');
    var pel_ciwajInfo       = $("#pelaku_ciwaj_info");
    
    //Global Vars Deskripsi Kejadian
    var dk_jenis            = $('#dk_jenis');
    var dk_jenisInfo        = $("#dk_jenis_info");
    var dk_lokasi           = $('#dk_lokasi');
    var dk_lokasiInfo       = $("#dk_lokasi_info");
    var dk_propinsi         = $('#dk_propinsi');
    var dk_propinsiInfo     = $("#dk_propinsi_info");
    var dk_kota             = $('#dk_kota');
    var dk_kotaInfo         = $("#dk_kota_info");
    var dk_alamat           = $('#dk_alamat');
    var dk_alamatInfo       = $("#dk_alamat_info");
    var dk_deskripsi        = $('#dk_deskripsi');
    var dk_deskripsiInfo    = $("#dk_deskripsi_info");
    var dk_security         = $("#dk_security");
    var dk_securityInfo     = $("#dk_security_info");
    var dk_num1             = $("#dk_qwe");
    var dk_num2             = $("#dk_ewq");
    
    //Bind Input
    kor_name.bind('keyup blur', function(){ validateName(kor_name, kor_nameInfo) });
    kor_tgllahir.bind('keyup blur', function(){ validateInput(kor_tgllahir, 'tanggal lahir korban', kor_tgllahirInfo) });
    kor_idcard.bind('keyup blur', function(){ validateID(kor_idcard, kor_idcardInfo) });
    kor_statushiv.bind('keyup change blur click', function(){ validateInput(kor_statushiv, 'status HIV korban', kor_statushivInfo) });
    kor_propinsi.bind('keyup change blur click', function(){ validateInput(kor_propinsi, 'propinsi korban', kor_propinsiInfo) });
    kor_kota.bind('keyup change blur click', function(){ validateInput(kor_kota, 'kota/kabupaten korban', kor_kotaInfo) });
    kor_hp.bind('keyup blur', function(){ validatePhone(kor_hp, kor_hpInfo, 0) });
    kor_email.bind('keyup blur', function(){ validateEmail(kor_email, kor_emailInfo, 0) });
    
    pel_name.bind('keyup blur', function(){ validateName(pel_name, pel_nameInfo) });
    pel_nick.bind('keyup blur', function(){ validateInput(pel_nick, 'nama panggilan pelaku', pel_nickInfo) });
    pel_jk.bind('keyup change blur click', function(){ validateInput(pel_jk, 'jenis kelamin pelaku', pel_jkInfo) });
    pel_noid.bind('keyup blur', function(){ validateID(pel_noid, pel_noidInfo) });
    pel_hub_kat.bind('keyup change blur click', function(){ validateInput(pel_hub_kat, 'hubungan kategori pelaku', pel_hub_katInfo) });
    pel_hub.bind('keyup change blur click', function(){ validateInput(pel_hub, 'hubungan pelaku', pel_hubInfo) });
    pel_telp.bind('keyup blur', function(){ validatePhone(pel_telp, pel_telpInfo, 0) });
    pel_email.bind('keyup blur', function(){ validateEmail(pel_email, pel_emailInfo, 0) });
    pel_jkus.bind('keyup change blur click', function(){ validateInput(pel_jkus, 'jenis kelamin pelaku', pel_jkusInfo) });
    pel_warkul.bind('keyup blur', function(){ validateInput(pel_warkul, 'warna kulit pelaku', pel_warkulInfo) });
    pel_tinggi.bind('keyup blur', function(){ validateInput(pel_tinggi, 'tinggi pelaku', pel_tinggiInfo) });
    pel_tanda.bind('keyup blur', function(){ validateInput(pel_tanda, 'tanda lain pelaku', pel_tandaInfo) });
    pel_karakter.bind('keyup blur', function(){ validateInput(pel_karakter, 'karakter tubuh pelaku', pel_karakterInfo) });
    pel_ciwaj.bind('keyup blur', function(){ validateInput(pel_ciwaj, 'ciri wajah pelaku', pel_ciwajInfo) });
    
    dk_jenis.bind('keyup change blur click', function(){ validateSelect(dk_jenis, 'jenis kekerasan', dk_jenisInfo) });
    dk_lokasi.bind('keyup change blur click', function(){ validateInput(dk_lokasi, 'lokasi kejadian', dk_lokasiInfo) });
    dk_propinsi.bind('keyup change blur click', function(){ validateInput(dk_propinsi, 'propinsi deskripsi kejadian', dk_propinsiInfo) });
    dk_kota.bind('keyup change blur click', function(){ validateInput(dk_kota, 'kota/kabupaten deskripsi kejadian', dk_kotaInfo) });
    dk_alamat.bind('keyup blur', function(){ validateInput(dk_alamat, 'alamat deskripsi kejadian', dk_alamatInfo) });
    dk_deskripsi.bind('keyup blur', function(){ validateInput(dk_deskripsi, 'deskripsi kejadian', dk_deskripsiInfo) });
    dk_security.bind('keyup change click', function(){ validateSecurity(dk_security, dk_num1, dk_num2, dk_securityInfo) });
    
    //On Submitting
    $('#button-report-korban1').click(function (e){
        e.preventDefault();

        if( validateName(kor_name, kor_nameInfo) & 
            validateInput(kor_tgllahir, 'tanggal lahir korban', kor_tgllahirInfo) &
            validateInput(kor_statushiv, 'status HIV korban', kor_statushivInfo) & 
            validateInput(kor_propinsi, 'propinsi korban', kor_propinsiInfo) & 
            validateInput(kor_kota, 'kota/kabupaten korban', kor_kotaInfo) ){
            unknown_suspect($('#pelaku_takdikenal_check'),$('#us'),$('#pelaku_dikenal'),$('#pelaku_takdikenal'));
            $('#wrapper-report1').hide();
            $('#wrapper-report2').fadeIn();
            $('html, body').animate({ scrollTop: $("#case-top").offset().top}, 500);
        }else{
            return false;
        }
        return false;
    });
    
    $('#button-report-korban2').click(function (e){
        e.preventDefault();
        
        if($('#us').val() == 1){
            if( validateInput(pel_jkus, 'jenis kelamin pelaku', pel_jkusInfo) &  
                validateInput(pel_warkul, 'warna kulit pelaku', pel_warkulInfo) & 
                validateInput(pel_tinggi, 'tinggi pelaku', pel_tinggiInfo) &
                validateInput(pel_tanda, 'tanda lain pelaku', pel_tandaInfo) & 
                validateInput(pel_karakter, 'karakter tubuh pelaku', pel_karakterInfo) &
                validateInput(pel_ciwaj, 'ciri wajah pelaku', pel_ciwajInfo) ){
                $('#wrapper-report2').hide();
                $('#wrapper-report3').fadeIn();
                $('html, body').animate({ scrollTop: $("#case-top").offset().top}, 500);
            }else{
                return false;
            }
        }else{
            if( validateName(pel_name, pel_nameInfo) &  
                validateInput(pel_nick, 'nama panggilan pelaku', pel_nickInfo) & 
                validateInput(pel_jk, 'jenis kelamin pelaku', pel_jkInfo) &
                validateInput(pel_hub_kat, 'hubungan kategori pelaku', pel_hub_katInfo) & 
                validateInput(pel_hub, 'hubungan pelaku', pel_hubInfo) ){
                $('#wrapper-report2').hide();
                $('#wrapper-report3').fadeIn();
                $('html, body').animate({ scrollTop: $("#case-top").offset().top}, 500);
            }else{
                return false;
            }
        }
        return false;
    });
    
    $('#button-report-korban3').click(function (e){        
        e.preventDefault();

        if( validateSelect(dk_jenis, 'jenis kekerasan', dk_jenisInfo) & 
            validateInput(dk_lokasi, 'lokasi kejadian', dk_lokasiInfo) &  
            validateInput(dk_propinsi, 'propinsi deskripsi kejadian', dk_propinsiInfo) & 
            validateInput(dk_kota, 'kota/kabupaten deskripsi kejadian', dk_kotaInfo) & 
            validateInput(dk_alamat, 'alamat deskripsi kejadian', dk_alamatInfo) & 
            validateInput(dk_deskripsi, 'deskripsi kejadian', dk_deskripsiInfo) &
            validateSecurity(dk_security, dk_num1, dk_num2, dk_securityInfo) ){
            
            var url = 'case_reporting/preview';
            
            $.ajax({
    			type : "POST",
    			url  : url,
    			data : kor_report_form.serialize(),
                beforeSend: function(){
                    $("div#mask").fadeIn();
                },
    			success: function(response) {
                    $('#wrapper-report3').hide();
                    $('#wrapper-report4').fadeIn();
                    $('#preview-page-korban').html(response);
                    $("div#mask").fadeOut();    
                    $('html, body').animate({ scrollTop: $("#case-top").offset().top}, 500);
    			}
    		});
        }else{
            return false;
        }
        return false;
    });
    
    $('#button-report-korban4').click(function (e){
        e.preventDefault();
        var url = 'case_reporting/insert';
            
        $.ajax({
			type : "POST",
			url  : url,
			data : kor_report_form.serialize(),
            beforeSend: function(){
                $("div#mask").fadeIn();
            },
			success: function(response) {
                if(response == '0'){
                    $("div#messages_report").fadeIn().html("<strong>ERROR: </strong>Input Report Kasus tidak berhasil! Silahkan cek kembali data yang anda masukkan."); 
                    $("div#mask").fadeOut();
                }else{
                    var obj = jQuery.parseJSON(response);
                    
                    $('#case_id').val(obj.case_id);
                    $('#wrapper-report4, #case-reporting-form').hide();
                    $('#thanks-page').fadeIn();
                    $("div#mask").fadeOut();
                    clearformall(kor_report_form);
                    unknown_suspect($('#pelaku_takdikenal_check'),$('#us'),$('#pelaku_dikenal'),$('#pelaku_takdikenal'));      
                    $('html, body').animate({ scrollTop: $("#case-top").offset().top}, 500);
                }
			}
		});
        return false;
    });
    
    $('#button-report-korban-prev1').click(function (e){
        e.preventDefault();
        $('#wrapper-report2').hide();
        $('#wrapper-report1').fadeIn();
        $('html, body').animate({ scrollTop: $("#case-top").offset().top}, 500);
    });
    
    $('#button-report-korban-prev2').click(function (e){
        e.preventDefault(); 
        unknown_suspect($('#pelaku_takdikenal_check'),$('#us'),$('#pelaku_dikenal'),$('#pelaku_takdikenal'));
        $('#wrapper-report3').hide();
        $('#wrapper-report2').fadeIn();
        $('html, body').animate({ scrollTop: $("#case-top").offset().top}, 500);
    });
    
    $('#button-report-korban-prev3').click(function (e){
        e.preventDefault(); 
        $('#wrapper-report4').hide();
        $('#wrapper-report3').fadeIn();
        $('html, body').animate({ scrollTop: $("#case-top").offset().top}, 500);
    });
    //==================================================================================================//
    
    
    //==================================================================================================//
    //----------------------------------- Case Reporting as Saksi --------------------------------------//
    //==================================================================================================//
    
    //Form Declaration
    var sak_report_form     = $("#saksi-report-form");
    
    //Global Vars Saksi
    var sak_name            = $("#saksi_name");
    var sak_nameInfo        = $("#saksi_name_info");
    var sak_tgllahir        = $("#saksi_tgllahir");
    var sak_tgllahirInfo    = $("#saksi_tgllahir_info");
    var sak_idcard          = $('#saksi_idcard');
    var sak_idcardInfo      = $("#saksi_idcard_info");
    var sak_propinsi        = $("#saksi_propinsi");
    var sak_propinsiInfo    = $("#saksi_propinsi_info");
    var sak_kota            = $("#saksi_kota");
    var sak_kotaInfo        = $("#saksi_kota_info");
    var sak_telp            = $("#saksi_telp");
    var sak_telpInfo        = $("#saksi_telp_info");
    var sak_email           = $("#saksi_email");
    var sak_emailInfo       = $("#saksi_email_info");
    var sak_hub_kat         = $('#saksi_hub_kat');
    var sak_hub_katInfo     = $("#saksi_hub_kat_info");
    var sak_hub             = $('#saksi_hub');
    var sak_hubInfo         = $("#saksi_hub_info");
    
    //Global Vars Korban 2
    var kor_name2           = $("#korban_name2");
    var kor_nameInfo2       = $("#korban_name2_info");
    var kor_tgllahir2       = $("#korban_tgllahir2");
    var kor_tgllahirInfo2   = $("#korban_tgllahir2_info");
    var kor_idcard2         = $("#korban_idcard2");
    var kor_idcardInfo2     = $("#korban_idcard2_info");
    var kor_propinsi2       = $("#korban_propinsi2");
    var kor_propinsiInfo2   = $("#korban_propinsi2_info");
    var kor_kota2           = $("#korban_kota2");
    var kor_kotaInfo2       = $("#korban_kota2_info");
    var kor_hp2             = $("#korban_hp2");
    var kor_hpInfo2         = $("#korban_hp2_info");
    var kor_email2          = $("#korban_email2");
    var kor_emailInfo2      = $("#korban_email2_info");
    var kor_statushiv2      = $("#korban_statushiv2");
    var kor_statushivInfo2  = $("#korban_statushiv2_info");
    
    //Global Vars Pelaku
    var pel_name2           = $('#pelaku_name2');
    var pel_nameInfo2       = $("#pelaku_name2_info");
    var pel_nick2           = $('#pelaku_nick2');
    var pel_nickInfo2       = $("#pelaku_nick2_info");
    var pel_jk2             = $('#pelaku_jk2');
    var pel_jkInfo2         = $("#pelaku_jk2_info");
    var pel_noid2           = $('#pelaku_noid2');
    var pel_noidInfo2       = $("#pelaku_noid2_info");
    var pel_hub_kat2        = $('#pelaku_hub_kat2');
    var pel_hub_katInfo2    = $("#pelaku_hub_kat2_info");
    var pel_hub2            = $('#pelaku_hub2');
    var pel_hubInfo2        = $("#pelaku_hub2_info");
    var pel_telp2           = $('#pelaku_telp2');
    var pel_telpInfo2       = $("#pelaku_telp2_info");
    var pel_email2          = $('#pelaku_email2');
    var pel_emailInfo2      = $("#pelaku_email2_info");
    var pel_jkus2           = $('#pelaku_jkus2');
    var pel_jkusInfo2       = $("#pelaku_jkus2_info");
    var pel_warkul2         = $('#pelaku_warkul2');
    var pel_warkulInfo2     = $("#pelaku_warkul2_info");
    var pel_tinggi2         = $('#pelaku_tinggi2');
    var pel_tinggiInfo2     = $("#pelaku_tinggi2_info");
    var pel_tanda2          = $('#pelaku_tanda2');
    var pel_tandaInfo2      = $("#pelaku_tanda2_info");
    var pel_karakter2       = $('#pelaku_karakter2');
    var pel_karakterInfo2   = $("#pelaku_karakter2_info");
    var pel_ciwaj2          = $('#pelaku_ciwaj2');
    var pel_ciwajInfo2      = $("#pelaku_ciwaj2_info");
    
    //Global Vars Deskripsi Kejadian
    var dk_jenis2           = $('#dk_jenis2');
    var dk_jenisInfo2       = $("#dk_jenis2_info");
    var dk_lokasi2          = $('#dk_lokasi2');
    var dk_lokasiInfo2      = $("#dk_lokasi2_info");
    var dk_propinsi2        = $('#dk_propinsi2');
    var dk_propinsiInfo2    = $("#dk_propinsi2_info");
    var dk_kota2            = $('#dk_kota2');
    var dk_kotaInfo2        = $("#dk_kota2_info");
    var dk_alamat2          = $('#dk_alamat2');
    var dk_alamatInfo2      = $("#dk_alamat2_info");
    var dk_deskripsi2       = $('#dk_deskripsi2');
    var dk_deskripsiInfo2   = $("#dk_deskripsi2_info");
    var dk_security2        = $("#dk_security2");
    var dk_securityInfo2    = $("#dk_security2_info");
    var dk_num1_2           = $("#dk_qwe2");
    var dk_num2_2           = $("#dk_ewq2");
    
    //Bind Input
    sak_name.bind('keyup blur', function(){ validateName(sak_name, sak_nameInfo) });
    sak_tgllahir.bind('keyup blur', function(){ validateInput(sak_tgllahir, 'tanggal lahir saksi', sak_tgllahirInfo) });
    sak_idcard.bind('keyup blur', function(){ validateID(sak_idcard, sak_idcardInfo) });
    sak_propinsi.bind('keyup change blur click', function(){ validateInput(sak_propinsi, 'propinsi saksi', sak_propinsiInfo) });
    sak_kota.bind('keyup change blur click', function(){ validateInput(sak_kota, 'kota/kabupaten saksi', sak_kotaInfo) });
    sak_email.bind('keyup blur', function(){ validateEmail(sak_email, sak_emailInfo, 0) });
    sak_telp.bind('keyup blur', function(){ validatePhone(sak_telp, sak_telpInfo, 0) });
    sak_hub_kat.bind('keyup change blur click', function(){ validateInput(sak_hub_kat, 'hubungan kategori saksi', sak_hub_katInfo) });
    sak_hub.bind('keyup change blur click', function(){ validateInput(sak_hub, 'hubungan saksi', sak_hubInfo) });
    
    kor_name2.bind('keyup blur', function(){ validateName(kor_name2, kor_nameInfo2) });
    kor_tgllahir2.bind('keyup blur', function(){ validateInput(kor_tgllahir2, 'tanggal lahir korban', kor_tgllahirInfo2) });
    kor_idcard2.bind('keyup blur', function(){ validateID(kor_idcard2, kor_idcardInfo2) });
    kor_propinsi2.bind('keyup change blur click', function(){ validateInput(kor_propinsi2, 'propinsi korban', kor_propinsiInfo2) });
    kor_kota2.bind('keyup change blur click', function(){ validateInput(kor_kota2, 'kota/kabupaten korban', kor_kotaInfo2) });
    kor_hp2.bind('keyup blur', function(){ validatePhone(kor_hp2, kor_hpInfo2, 0) });
    kor_email2.bind('keyup blur', function(){ validateEmail(kor_email2, kor_emailInfo2, 0) });
    kor_statushiv2.bind('keyup change blur click', function(){ validateInput(kor_statushiv2, 'status HIV korban', kor_statushivInfo2) });
    
    pel_name2.bind('keyup blur', function(){ validateName(pel_name2, pel_nameInfo2) });
    pel_nick2.bind('keyup blur', function(){ validateInput(pel_nick2, 'nama panggilan pelaku', pel_nickInfo2) });
    pel_jk2.bind('keyup change blur click', function(){ validateInput(pel_jk2, 'jenis kelamin pelaku', pel_jkInfo2) });
    pel_noid2.bind('keyup blur', function(){ validateID(pel_noid2, pel_noidInfo2) });
    pel_hub_kat2.bind('keyup change blur click', function(){ validateInput(pel_hub_kat2, 'hubungan kategori pelaku', pel_hub_katInfo2) });
    pel_hub2.bind('keyup change blur click', function(){ validateInput(pel_hub2, 'hubungan pelaku', pel_hubInfo2) });
    pel_telp2.bind('keyup blur', function(){ validatePhone(pel_telp2, pel_telpInfo2, 0) });
    pel_email2.bind('keyup blur', function(){ validateEmail(pel_email2, pel_emailInfo2, 0) });
    
    pel_jkus2.bind('keyup change blur click', function(){ validateInput(pel_jkus2, 'jenis kelamin pelaku', pel_jkusInfo2) });
    pel_warkul2.bind('keyup blur', function(){ validateInput(pel_warkul2, 'warna kulit pelaku', pel_warkulInfo2) });
    pel_tinggi2.bind('keyup blur', function(){ validateInput(pel_tinggi2, 'tinggi pelaku', pel_tinggiInfo2) });
    pel_tanda2.bind('keyup blur', function(){ validateInput(pel_tanda2, 'tanda lain pelaku', pel_tandaInfo2) });
    pel_karakter2.bind('keyup blur', function(){ validateInput(pel_karakter2, 'karakter tubuh pelaku', pel_karakterInfo2) });
    pel_ciwaj2.bind('keyup blur', function(){ validateInput(pel_ciwaj2, 'ciri wajah pelaku', pel_ciwajInfo2) });
    
    dk_jenis2.bind('keyup change blur click', function(){ validateSelect(dk_jenis2, 'jenis kekerasan', dk_jenisInfo2) });
    dk_lokasi2.bind('keyup change blur click', function(){ validateInput(dk_lokasi2, 'lokasi kejadian', dk_lokasiInfo2) });
    dk_propinsi2.bind('keyup change blur click', function(){ validateInput(dk_propinsi2, 'propinsi deskripsi kejadian', dk_propinsiInfo2) });
    dk_kota2.bind('keyup change blur click', function(){ validateInput(dk_kota2, 'kota/kabupaten deskripsi kejadian', dk_kotaInfo2) });
    dk_alamat2.bind('keyup blur', function(){ validateInput(dk_alamat2, 'alamat deskripsi kejadian', dk_alamatInfo2) });
    dk_deskripsi2.bind('keyup blur', function(){ validateInput(dk_deskripsi2, 'deskripsi kejadian', dk_deskripsiInfo2) });
    dk_security2.bind('keyup change click', function(){ validateSecurity(dk_security2, dk_num1_2, dk_num2_2, dk_securityInfo2) });
    
    $('#button-report-saksi1').click(function (e){        
        e.preventDefault();
        
        if( validateName(sak_name, sak_nameInfo) &
            validateInput(sak_tgllahir, 'tanggal lahir saksi', sak_tgllahirInfo) &
            validateInput(sak_propinsi, 'propinsi saksi', sak_propinsiInfo) &
            validateInput(sak_kota, 'kota/kabupaten saksi', sak_kotaInfo) &
            validateInput(sak_hub_kat, 'hubungan kategori saksi', sak_hub_katInfo) & 
            validateInput(sak_hub, 'hubungan saksi', sak_hubInfo) ){
            $('#wrapper-report-saksi1').hide();
            $('#wrapper-report-saksi2').fadeIn();
            $('html, body').animate({ scrollTop: $("#case-top").offset().top}, 500);
        }else{
            return false;
        }
        return false;
    });
    
    $('#button-report-saksi2').click(function (e){        
        e.preventDefault();
        
        if( validateName(kor_name2, kor_nameInfo2) & 
            validateInput(kor_tgllahir2, 'tanggal lahir korban', kor_tgllahirInfo2) &
            validateInput(kor_propinsi2, 'propinsi korban', kor_propinsiInfo2) & 
            validateInput(kor_kota2, 'kota/kabupaten korban', kor_kotaInfo2) &  
            validateInput(kor_statushiv2, 'status HIV korban', kor_statushivInfo2) ){
            unknown_suspect($('#pelaku_takdikenal_check2'),$('#us2'),$('#pelaku_dikenal2'),$('#pelaku_takdikenal2'));
            $('#wrapper-report-saksi2').hide();
            $('#wrapper-report-saksi3').fadeIn();
            $('html, body').animate({ scrollTop: $("#case-top").offset().top}, 500);
        }else{
            return false;
        }
        return false;
    });
    
    $('#button-report-saksi3').click(function (e){        
        e.preventDefault();
        
        if($('#us2').val() == 1){
            if( validateInput(pel_jkus2, 'jenis kelamin pelaku', pel_jkusInfo2) &  
                validateInput(pel_warkul2, 'warna kulit pelaku', pel_warkulInfo2) & 
                validateInput(pel_tinggi2, 'tinggi pelaku', pel_tinggiInfo2) &
                validateInput(pel_tanda2, 'tanda lain pelaku', pel_tandaInfo2) & 
                validateInput(pel_karakter2, 'karakter tubuh pelaku', pel_karakterInfo2) &
                validateInput(pel_ciwaj2, 'ciri wajah pelaku', pel_ciwajInfo2) ){
                $('#wrapper-report-saksi3').hide();
                $('#wrapper-report-saksi4').fadeIn();
                $('html, body').animate({ scrollTop: $("#case-top").offset().top}, 500);
            }else{
                return false;
            }
        }else{
            if( validateName(pel_name2, pel_nameInfo2) &  
                validateInput(pel_nick2, 'nama panggilan pelaku', pel_nickInfo2) & 
                validateInput(pel_jk2, 'jenis kelamin pelaku', pel_jkInfo2) &
                validateInput(pel_hub_kat2, 'hubungan kategori pelaku', pel_hub_katInfo2) & 
                validateInput(pel_hub2, 'hubungan pelaku', pel_hubInfo2) ){
                $('#wrapper-report-saksi3').hide();
                $('#wrapper-report-saksi4').fadeIn();
                $('html, body').animate({ scrollTop: $("#case-top").offset().top}, 500);
            }else{
                return false;
            }
        }
        return false;
    });
    
    $('#button-report-saksi4').click(function (e){        
        e.preventDefault();

        if( validateSelect(dk_jenis2, 'jenis kekerasan', dk_jenisInfo2) &
            validateInput(dk_lokasi2, 'lokasi kejadian', dk_lokasiInfo2) &
            validateInput(dk_propinsi2, 'propinsi deskripsi kejadian', dk_propinsiInfo2) &
            validateInput(dk_kota2, 'kota/kabupaten deskripsi kejadian', dk_kotaInfo2) &
            validateInput(dk_alamat2, 'alamat deskripsi kejadian', dk_alamatInfo2) &
            validateInput(dk_deskripsi2, 'deskripsi kejadian', dk_deskripsiInfo2) &
            validateSecurity(dk_security2, dk_num1_2, dk_num2_2, dk_securityInfo2) ){
            
            var url = 'case_reporting/preview';
            
            $.ajax({
    			type : "POST",
    			url  : url,
    			data : sak_report_form.serialize(),
                beforeSend: function(){
                    $("div#mask").fadeIn();
                },
    			success: function(response) {
                    $('#wrapper-report-saksi4').hide();
                    $('#wrapper-report-saksi5').fadeIn();
                    $('#preview-page-saksi').html(response);
                    $("div#mask").fadeOut();    
                    $('html, body').animate({ scrollTop: $("#case-top").offset().top}, 500);
    			}
    		});
            
        }else{
            return false;
        }
        return false;
    });
    
    $('#button-report-saksi5').click(function (e){        
        e.preventDefault();
        var url = 'case_reporting/insert';
            
        $.ajax({
			type : "POST",
			url  : url,
			data : sak_report_form.serialize(),
            beforeSend: function(){
                $("div#mask").fadeIn();
            },
			success: function(response) {
                if(response == '0'){
                    $("div#messages_report").fadeIn().html("<strong>ERROR: </strong>Input Report Kasus tidak berhasil! Silahkan cek kembali data yang anda masukkan."); 
                    $("div#mask").fadeOut();
                }else{
                    var obj = jQuery.parseJSON(response);
                    
                    $('#case_id').val(obj.case_id);
                    $('#wrapper-report-saksi5, #case-reporting-form').hide();
                    $('#thanks-page').fadeIn();
                    $("div#mask").fadeOut();
                    clearformall(sak_report_form);
                    unknown_suspect($('#pelaku_takdikenal_check2'),$('#us2'),$('#pelaku_dikenal2'),$('#pelaku_takdikenal2'));
                    $('html, body').animate({ scrollTop: $("#case-top").offset().top}, 500);
                }
			}
		});
        return false;
    });
    
    $('#button-report-saksi-prev1').click(function (e){
        e.preventDefault();
        $('#wrapper-report-saksi2').hide();
        $('#wrapper-report-saksi1').fadeIn();
        $('html, body').animate({ scrollTop: $("#case-top").offset().top}, 500);
    });
    
    $('#button-report-saksi-prev2').click(function (e){
        e.preventDefault();
        $('#wrapper-report-saksi3').hide();
        $('#wrapper-report-saksi2').fadeIn();
        $('html, body').animate({ scrollTop: $("#case-top").offset().top}, 500);
    });
    
    $('#button-report-saksi-prev3').click(function (e){
        e.preventDefault();
        unknown_suspect($('#pelaku_takdikenal_check2'),$('#us2'),$('#pelaku_dikenal2'),$('#pelaku_takdikenal2'));
        $('#wrapper-report-saksi4').hide();
        $('#wrapper-report-saksi3').fadeIn();
        $('html, body').animate({ scrollTop: $("#case-top").offset().top}, 500);
    });
    
    $('#button-report-saksi-prev4').click(function (e){
        e.preventDefault(); 
        $('#wrapper-report-saksi5').hide();
        $('#wrapper-report-saksi4').fadeIn();
        $('html, body').animate({ scrollTop: $("#case-top").offset().top}, 500);
    });
    //==================================================================================================//
    
    
    //==================================================================================================//
    //-------------------------------------------- Donation --------------------------------------------//
    //==================================================================================================//
    
    //Form Declaration for Make Donation
    var make_don_form       = $("#make-donation-form");
    
    //Global Vars Make Donation
    var don_jum             = $('#donasi_jum');
    var don_jumInfo         = $("#donasi_jum_info");
    var don_kat             = $('#donasi_kat');
    var don_katInfo         = $("#donasi_kat_info");
    
    //Bind Input
    don_jum.bind('keyup change blur click', function(){ validateInput(don_jum, 'jumlah donasi', don_jumInfo) });
    don_kat.bind('keyup change blur click', function(){ validateInput(don_kat, 'kategori donasi', don_katInfo) });
    
    //On Submit
    $('#button-donasi-send').click(function (e){        
        e.preventDefault();

        if( validateInput(don_jum, 'jumlah donasi', don_jumInfo) & 
            validateInput(don_kat, 'kategori donasi', don_katInfo) ){
            var url = 'donation/insert';
            
            $.ajax({
    			type : "POST",
    			url  : url,
    			data : make_don_form.serialize(),
                beforeSend: function(){
                    $("div#mask").fadeIn('slow');
                },
    			success: function(response) {
                    $('html, body').animate({ scrollTop: $("#donation").offset().top}, 500);
                    if(response == "0"){
                        $("div#mask").delay(2000).fadeOut('slow', function(){
                            $("#messages_donation").removeClass("alert-success").addClass("alert-danger");
                            $("#messages_donation").fadeIn().html("<strong>ERROR: </strong>Maaf, ada kesalahan dengan data donasi Anda.").delay(5000).fadeOut(); 
                        });
                    }else{
                        var obj = jQuery.parseJSON(response);
                        
                        $("div#mask").delay(2000).fadeOut('slow', function(){
                            $('#don_id').val(obj.id_donasi);
                            $('#donasi_conf_jum').val(obj.jumlah_donasi);
                            $('#donasi_conf_tgl').val(obj.datecreated.substr(0,10));
                            $('#md1').hide();
                            $('#md2').fadeIn();
                            
                            var text = "<strong>Success: </strong>Terima Kasih. Silahkan melakukan konfirmasi untuk donasi Anda!";
                            $("#messages_donation").removeClass("alert-danger").addClass("alert-success");
                            $("#messages_donation").fadeIn().html(text).delay(5000).fadeOut();
                            
                        });
                        
                        clearformall(make_don_form);
                        clearformall($("#confirm-donation-form"));
                    }
    			}
    		});
        }else{
            return false;
        }
        return false;
    });
    
    
    //Form Declaration for Confirmation Donation
    var conf_don_form       = $("#confirm-donation-form");
    
    //Global Vars Make Donation
    var don_conf_kat        = $('#donasi_conf_kat');
    var don_conf_katInfo    = $("#donasi_conf_kat_info");
    var don_conf_jum        = $('#donasi_conf_jum');
    var don_conf_jumInfo    = $("#donasi_conf_jum_info");
    var don_conf_tgl        = $('#donasi_conf_tgl');
    var don_conf_tglInfo    = $("#donasi_conf_tgl_info");
    var don_conf_cara       = $('#donasi_conf_cara');
    var don_conf_caraInfo   = $("#donasi_conf_cara_info");
    var don_conf_ba         = $('#donasi_conf_bankasal');
    var don_conf_baInfo     = $("#donasi_conf_bankasal_info");
    var don_conf_ra         = $('#donasi_conf_rekasal');
    var don_conf_raInfo     = $("#donasi_conf_rekasal_info");
    var don_conf_brtuj      = $('#donasi_conf_brtuj');
    var don_conf_brtujInfo  = $("#donasi_conf_brtuj_info");
    
    //Bind Input
    don_conf_kat.bind('keyup change blur click', function(){ validateInput(don_conf_kat, 'kategori donasi', don_conf_katInfo) });
    don_conf_jum.bind('keyup change blur click', function(){ validateInput(don_conf_jum, 'jumlah donasi', don_conf_jumInfo) });
    don_conf_tgl.bind('keyup change blur click', function(){ validateInput(don_conf_tgl, 'tanggal donasi', don_conf_tglInfo) });
    don_conf_cara.bind('keyup change blur click', function(){ validateInput(don_conf_cara, 'tanggal donasi', don_conf_caraInfo) });
    don_conf_ba.bind('keyup change blur click', function(){ validateInput(don_conf_ba, 'bank asal donasi', don_conf_baInfo) });
    don_conf_ra.bind('keyup change blur click', function(){ validateInput(don_conf_ra, 'rekening asal donasi', don_conf_raInfo) });
    don_conf_brtuj.bind('keyup change blur click', function(){ validateInput(don_conf_brtuj, 'bank dan rekening tujuan donasi', don_conf_brtujInfo) });
    
    //On Submit
    $('#button-donasi-conf-send').click(function (e){        
        e.preventDefault();

        if( validateInput(don_conf_kat, 'kategori donasi', don_conf_katInfo) & 
            validateInput(don_conf_jum, 'jumlah donasi', don_conf_jumInfo) & 
            validateInput(don_conf_tgl, 'tanggal donasi', don_conf_tglInfo) & 
            validateInput(don_conf_cara, 'tanggal donasi', don_conf_caraInfo) & 
            validateInput(don_conf_ba, 'bank asal donasi', don_conf_baInfo) &
            validateInput(don_conf_ra, 'rekening asal donasi', don_conf_raInfo) & 
            validateInput(don_conf_brtuj, 'bank dan rekening tujuan donasi', don_conf_brtujInfo) ){
                
            var url = 'donation/confirmation';
            
            $.ajax({
    			type : "POST",
    			url  : url,
    			data : conf_don_form.serialize(),
                beforeSend: function(){
                    $("div#mask").fadeIn();
                },
    			success: function(response) {
                    $('html, body').animate({ scrollTop: $("#donation").offset().top}, 500);
                    if( response == "1" ){
                        $("div#mask").delay(2000).fadeOut('slow', function(){
                            $('#don_id').val('');
                            $('#md2').hide();
                            $('#md1').fadeIn();
                            $('#tab-md2').trigger('click');
                            
                            var text = "<strong>Success: </strong>Terima Kasih atas konfirmasi donasi Anda";
                            $("#messages_donation").removeClass("alert-danger").addClass("alert-success");
                            $("#messages_donation").fadeIn().html(text).delay(5000).fadeOut();
                        });
                        
                        clearformall(conf_don_form);
                    }else{
                        $("div#mask").delay(2000).fadeOut('slow', function(){
                            $("#messages_donation").removeClass("alert-success").addClass("alert-danger");
                            $("#messages_donation").fadeIn().html("<strong>ERROR: </strong>Maaf, ada kesalahan dengan data donasi Anda.").delay(5000).fadeOut(); 
                        });
                    }
    			}
    		});
        }else{
            return false;
        }
        return false;
    });
    
    function _load_donation( url ){
        var url     = typeof(url) != 'undefined' ? url : 'donation/load_donation';
        var eld     = $("#list-don");
        var pagd    = $("#pagination_donation");
        
        clearformall($("#make-donation-form"));
        clearformall($("#confirm-donation-form"));
        $('#md2').hide();
        $('#md1').show();
        
        $.ajax({
			type : "GET",
			url  : url,
			data : {
                'search_tanggal'    : $('#don_tanggal').val(),
                'search_status'     : $('#don_status').val(),
                'search_kategori'   : $('#don_kat').val(),
                'search_val'        : $('#search_donation').val(),
            },
            beforeSend: function(){
                $(eld).empty();
                $('#don_id').val('');
                $("div#mask").fadeIn();
            },
			success: function(response) {            
                response = $.parseJSON(response);
                $('html, body').animate({ scrollTop: $("#donation").offset().top}, 500);
                
                if(response.donation == ""){
                    $(eld).hide().empty();
                    $(eld).html(response.donation).fadeIn('fast');
                    $(pagd).hide().empty();
                    $("div#mask").fadeOut();
                }else{
                    $("div#mask").delay(0).fadeOut('slow', function(){
                        $(eld).hide().empty();
                        $(eld).html(response.donation).fadeIn('fast');
                        $(pagd).hide().empty();
                        $(pagd).html(response.pagination).fadeIn('fast');
                        
                        // Donation Pagination
                        $('.pagination_donation').each(function(){
                            $(this).click(function(){
                                _load_donation( $(this).attr('href') );
                                return false;
                            });
                        });
                        
                        // Donation Details
                        $('a.btn-det').click(function (e){        
                            e.preventDefault();
                            var id  = parseInt( $(this).attr('id') );
                            var det = $('#don-det-' + id);
                            
                            if(det.is(':visible')){
                                det.fadeOut();
                            }else{
                                det.fadeIn();
                            }
                            return false;
                        });
                        
                        // Donation Confirmation
                        $('a.btn-conf').click(function (e){        
                            e.preventDefault();
                            var id      = parseInt( $(this).attr('id') );
                            var url_don = 'donation/get_donation';
                            
                            $.ajax({
                    			type : "POST",
                    			url  : url_don,
                    			data : {'id_donasi': id},
                                beforeSend: function(){
                                    $("div#mask").fadeIn();
                                },
                    			success: function(response) {
                                    $('html, body').animate({ scrollTop: $("#donation").offset().top}, 500);
                                    if(response != "0"){
                                        var obj = jQuery.parseJSON(response);
                                        
                                        $("div#mask").delay(500).fadeOut('slow', function(){
                                            $('#don_id').val(id);
                                            $('#donasi_conf_kat').val(obj.kategori);
                                            $('#donasi_conf_jum').val(obj.jumlah_donasi);
                                            $('#donasi_conf_tgl').val(obj.datecreated.substr(0,10));
                                            $('#md1').hide();
                                            $('#md2').fadeIn();
                                            $('#tab-md1').trigger('click'); 
                                        });
                                    }
                                    return false;
                    			}
                    		});
                        });
                    });
                }
                return false;
			}
		});
    }
    
    $('#tab-md2, #tab-panel-md2').click(function (){
        $('#don_tanggal').val('');
        $('#don_status').val('');
        $('#search_donation').val('');
        _load_donation();
    });
    
    $('#tab-md1, #tab-panel-md1').click(function (){
        $('html, body').animate({ scrollTop: $("#donation").offset().top}, 500);
    });
    
    $('#btn_search_donation').click(function (){ 
        _load_donation();
        return false;
    });
    
    $('#button-donasi-conf-cancel').click(function (e){        
        e.preventDefault();
        $('#md2').hide();
        $('#md1').fadeIn();
        $('html, body').animate({ scrollTop: $("#donation").offset().top}, 500);
    });
    //==================================================================================================//
    
    
    //==================================================================================================//
    //----------------------------------------- Unknown Suspect ----------------------------------------//
    //==================================================================================================//
    
    // Event Pelaku Tak Dikenal as Korban Change
    $('#pelaku_takdikenal_check').change(function(e) {
        e.preventDefault();
        unknown_suspect($(this),$('#us'),$('#pelaku_dikenal'), $('#pelaku_takdikenal'));
        return false;
    }).change();
    
    // Event Pelaku Tak Dikenal as Saksi Change
    $('#pelaku_takdikenal_check2').change(function(e) {
        e.preventDefault();
        unknown_suspect($(this),$('#us2'),$('#pelaku_dikenal2'), $('#pelaku_takdikenal2'));
        return false;
    }).change();
    
    // Pelaku Tak Dikenal Condition
    function unknown_suspect(el, us, us1, us2){
        if (el.is(':checked')) {
            us.val('1');
            us1.slideUp();
            us2.slideDown();
            $('html, body').animate({ scrollTop: $("#case-top").offset().top}, 500);
        }else if(el.is(":not(':checked')")){
            us.val('0');
            us2.slideUp();
            us1.slideDown();
        }
    }
    //==================================================================================================//
    
    
    //==================================================================================================//
    //----------------------------------------- Thank You Page -----------------------------------------//
    //==================================================================================================//
    $('#button-back-to-case').click(function (e){
        e.preventDefault();
        $('#case_id').val('');
        $('#case-reporting-form, #thanks-page').hide();
        $('#agreement-form').fadeIn();
        $('html, body').animate({ scrollTop: $("#case-top").offset().top}, 500);
    });
    //==================================================================================================//
    
    
    //==================================================================================================//
    //----------------------------------------- Agreement Form -----------------------------------------//
    //==================================================================================================//
    $('#button-agreement').click(function (e){
        e.preventDefault();
        var info        = $('#agreement_check_info');
        var agree_form  = $('#agreement-form');
        var case_form   = $('#case-reporting-form');
        
        if( $('#agreement_check').is(':checked') ){
            agree_form.hide();
            case_form.fadeIn();
            $('#thanks-page').hide();
            $('#wrapper-report1, #wrapper-report-saksi1').fadeIn();
            $('#agreement_check, #pelaku_takdikenal_check').prop('checked', false);
            $('#case-reporting-form').find('.nav-tabs > li:first-child').addClass('active');
            $('#case-reporting-form').find('.nav-tabs > li:last-child').removeClass('active');
            $('#case-reporting-form').find('.tab-content > li > #tab-korban').addClass('active in').show().css('height','auto');
            $('#case-reporting-form').find('.tab-content > li > #tab-saksi').removeClass('active in').hide().css('height','0');
            $('html, body').animate({ scrollTop: $("#case-top").offset().top}, 500);
        }else{
            info.text("Jika Anda ingin mengisi form laporan kasus, silahkan check box persetujuan di atas!");
			info.addClass("messages alert-danger registration").css('display','block');
			return false;
        }
        return false;
    });
    
    $('#agreement_check').change(function(e) {
        e.preventDefault();
        var info = $('#agreement_check_info');
        if ($(this).is(':checked')) {
            info.fadeOut();
            return true;
        }
    });
    //==================================================================================================//
    
    
    //==================================================================================================//
    //------------------------------------------ Follow Up ---------------------------------------------//
    //==================================================================================================//
    
    //Global Vars Follow Up
    var tl          = $('#tl');
    var tlInfo      = $("#tl_info");
    
    $('#button-tl-submit').click(function (e){
        e.preventDefault();
        
        if( validateInput(tl, 'tindak lanjut pengaduan/pelaporan', tlInfo) ){
            var tl_telp         = $('#tl_telp');
            var tl_telpInfo     = $("#tl_telp_info");
            
            tl_telp.bind('keyup blur', function(){ validatePhone(tl_telp, tl_telpInfo, 1) });
            
            if( validatePhone( tl_telp, tl_telpInfo, 1) ){
                var url = 'case_reporting/case_followup';
            
                $.ajax({
        			type : "POST",
        			url  : url,
        			data : {
                        'case_id'   : $('#case_id').val(),
                        'tl_value'  : $('#tl').val(),
                        'tl_telp'   : $('#tl_telp').val(),
        			},
        			success: function(response) {                     
                        if(response == '0'){
                            $("div#messages_report").fadeIn().html("<strong>ERROR: </strong>Input Tindak Lanjut Pengaduan/Pelaporan tidak berhasil!"); 
                        }else{
                            $('#tl-form').hide();
                            $('#case_id, #tl, #tl_telp').val('');
                            $('#agreement-form').fadeIn();
                            $('html, body').animate({ scrollTop: $("#case-top").offset().top}, 500);
                        }
        			}
        		});
            }
        }else{
            return false;
        }
        return false;
    });
    
    $('#button-tl-back').click(function (e){
        e.preventDefault();
        $('#tl-form').hide();
        $('#agreement-form').fadeIn();
        $('html, body').animate({ scrollTop: $("#case-top").offset().top}, 500);
    });
    
    $('#tl').change(function(){
        var text    = "";
        var email   = "";
        var val     = $(this).val();
    
        $("#tl_info").hide();
        $('#tl_telp').val('');
        $("#tl_telp_info").hide();
        
        if(val == "hanya melapor"){
            text    = 'Jika Anda ingin menindaklanjuti laporan Anda silahkan kirimkan email dengan subject "Berubah Pikiran" atau hubungi kami di 021-471 2484.';
            email   = 'Email : <a href="mailto:legal.advice@ippi.or.id"><abbr>legal.advice@ippi.or.id</abbr></a>';
        }else if(val == "butuh saran hukum"){
            text    = 'Silahkan meninggalkan nomor telp yang bisa dihubungi atau silahkan kirimkan email dengan subject "Saran Hukum", sebutkan user ID Anda saat login';
            email   = 'Email :  <a href="mailto:legal.advice@ippi.or.id"><abbr>konseling.vaw@ippi.or.id</abbr></a>';
        }else if(val == "konseling"){
            text    = 'Silahkan meninggalkan nomor telp yang bisa dihubungi atau silahkan kirimkan email dengan subject "Konseling", sebutkan user ID Anda saat login';
            email   = 'Email : <a href="mailto:legal.advice@ippi.or.id"><abbr>konseling.vaw@ippi.or.id</abbr></a>';
        }else if(val == "layanan kesehatan"){
            text    = 'Silahkan meninggalkan nomor telp yang bisa dihubungi atau silahkan kirimkan email dengan subject "Layanan Kesehatan", sebutkan user ID Anda saat login';
            email   = 'Email :  <a href="mailto:legal.advice@ippi.or.id"><abbr>konseling.vaw@ippi.or.id</abbr></a>';
        }
        
        if(text != "" && email != ""){
            $('#tl_content').fadeIn(500);
            $('#tl_text').html(text);
            $('#tl_emailtext').html(email);
        }else{
            $('#tl_content').fadeOut();
        }
        return false;
    }).change();
    
    $('#button-pengaduan, #button-pengaduan2').click(function (e){        
        e.preventDefault();
        $('#case-reporting-form, #thanks-page, #tl_content').hide();
        $('#tl-form').fadeIn();
        $('#tl, #tl_telp').val('');
        $('html, body').animate({ scrollTop: $("#case-top").offset().top}, 500);
    });
    //==================================================================================================//
    
    
    //==================================================================================================//
    //-------------------------------------- Checkout Validation ---------------------------------------//
    //==================================================================================================//
    
    //Form Declaration
    var co_form             = $("#checkout-form");
    
    //Global Vars
    var co_nama             = $("#co_nama");
    var co_namaInfo         = $("#co_nama_info");
    var co_email            = $('#co_email');
    var co_emailInfo        = $("#co_email_info");
    var co_propinsi         = $('#co_propinsi');
    var co_propinsiInfo     = $("#co_propinsi_info");
    var co_kota             = $('#co_kota');
    var co_kotaInfo         = $("#co_kota_info");
    var co_alamat           = $('#co_alamat');
    var co_alamatInfo       = $("#co_alamat_info");
    var co_kodepos          = $('#co_kodepos');
    var co_kodeposInfo      = $("#co_kodepos_info");
    var co_phone            = $('#co_phone');
    var co_phoneInfo        = $("#co_phone_info");
    
    var cos_nama            = $("#cos_nama");
    var cos_namaInfo        = $("#cos_nama_info");
    var cos_propinsi        = $('#cos_propinsi');
    var cos_propinsiInfo    = $("#cos_propinsi_info");
    var cos_kota            = $('#cos_kota');
    var cos_kotaInfo        = $("#cos_kota_info");
    var cos_alamat          = $('#cos_alamat');
    var cos_alamatInfo      = $("#cos_alamat_info");
    var cos_kodepos         = $('#cos_kodepos');
    var cos_kodeposInfo     = $("#cos_kodepos_info");
    var cos_phone           = $('#cos_phone');
    var cos_phoneInfo       = $("#cos_phone_info");
    
    var co_payment          = $('#co_payment');
    var co_paymentInfo      = $("#co_payment_info");
    var co_cityto           = $('#co_cityto');
    var co_citytoInfo       = $("#co_cityto_info");
    var co_paket            = $('#co_paket');
    var co_paketInfo        = $("#co_paket_info");
    
    // Reset Form On Refresh
    clearformall(co_form);
    $('#co_ship_this').prop("checked", true);
    
    //Bind Input
    co_nama.bind('keyup blur', function(){ validateName(co_nama, co_namaInfo) });
    co_email.bind('keyup blur', function(){ validateEmail(co_email, co_emailInfo, 1) });
    co_propinsi.bind('keyup change blur click', function(){ validateInput(co_propinsi, 'propinsi', co_propinsiInfo) });
    co_kota.bind('keyup change blur click', function(){ validateInput(co_kota, 'kota/kabupaten', co_kotaInfo) });
    co_alamat.bind('keyup blur', function(){ validateInput(co_alamat, 'alamat', co_alamatInfo) });
    co_kodepos.bind('keyup blur', function(){ validateInput(co_kodepos, 'kodepos', co_kodeposInfo) });
    co_phone.bind('keyup blur', function(){ validatePhone(co_phone, co_phoneInfo, 1) });
    
    cos_nama.bind('keyup blur', function(){ validateName(cos_nama, cos_namaInfo) });
    cos_propinsi.bind('keyup change blur click', function(){ validateInput(cos_propinsi, 'propinsi', cos_propinsiInfo) });
    cos_kota.bind('keyup change blur click', function(){ validateInput(cos_kota, 'kota/kabupaten', cos_kotaInfo) });
    cos_alamat.bind('keyup blur', function(){ validateInput(cos_alamat, 'alamat', cos_alamatInfo) });
    cos_kodepos.bind('keyup blur', function(){ validateInput(cos_kodepos, 'kodepos', cos_kodeposInfo) });
    cos_phone.bind('keyup blur', function(){ validatePhone(cos_phone, cos_phoneInfo, 1) });
    
    co_payment.bind('keyup change blur click', function(){ validateInput(co_payment, 'payment method', co_paymentInfo) });
    co_cityto.bind('keyup blur', function(){ validateInput(co_cityto, 'kota pengiriman', co_citytoInfo) });
    co_paket.bind('keyup change blur click', function(){ validateInput(co_paket, 'paket pengiriman', co_paketInfo) });
    
    // On Submitting
    // Billing Information Validation
    $('#button-checkout1').click(function (e){
        e.preventDefault();
        
        if( validateName(co_nama, co_namaInfo) & 
            validateEmail(co_email, co_emailInfo, 1) &
            validateInput(co_propinsi, 'propinsi', co_propinsiInfo) & 
            validateInput(co_kota, 'kota/kabupaten', co_kotaInfo) & 
            validateInput(co_alamat, 'alamat', co_alamatInfo) & 
            validateInput(co_kodepos, 'kodepos', co_kodeposInfo) & 
            validatePhone(co_phone, co_phoneInfo, 1) ){
                
            var ship_val    = $('input[name=co_ship]:checked').val();
            
            $("div#mask").fadeIn().delay(1000).fadeOut(function(){
                $('#billing_info').hide();
                if(ship_val == 'ship_this'){
                    $('#payment_info').fadeIn();
                }else{
                    $('#shipping_info').fadeIn();
                }
                $('html, body').animate({ scrollTop: $("#fundrising").offset().top}, 500); 
            });
        }
        return false;
    });
    
    // Shipping Information Validation
    $('#button-checkout2').click(function (e){
        e.preventDefault();

        if( validateName(cos_nama, cos_namaInfo) & 
            validateInput(cos_propinsi, 'propinsi', cos_propinsiInfo) & 
            validateInput(cos_kota, 'kota/kabupaten', cos_kotaInfo) & 
            validateInput(cos_alamat, 'alamat', cos_alamatInfo) & 
            validateInput(cos_kodepos, 'kodepos', cos_kodeposInfo) & 
            validatePhone(cos_phone, cos_phoneInfo, 1) ){
            $("div#mask").fadeIn().delay(1000).fadeOut(function(){
                $('#shipping_info').hide();
                $('#payment_info').fadeIn();
                $('html, body').animate({ scrollTop: $("#fundrising").offset().top}, 500);
            });
        }
        return false;
    });
    
    // Payment Information Validation
    $('#button-checkout3').click(function (e){
        e.preventDefault();
    
        if( validateInput(co_payment, 'payment method', co_paymentInfo) & 
            validateInput(co_cityto, 'kota pengiriman', co_citytoInfo) & 
            validateInput(co_paket, 'paket pengiriman', co_paketInfo) ){
                
            _load_cartlist_review();
            $("div#mask").fadeIn().delay(1000).fadeOut(function(){
                $('#payment_info').hide();
                $('#order_review').fadeIn();
                $('html, body').animate({ scrollTop: $("#fundrising").offset().top}, 500); 
            });
        }
        return false;
    });
    
    // Payment Information Validation
    $('#button-order').click(function (e){
        e.preventDefault();
        
        var url = window.location.origin + "/fundrising/order";
        var msg = $('#order_message');
        
        $.ajax({
            type: "POST",
            data: co_form.serialize(),
            url: url,
            beforeSend: function (){
                $("div#mask").fadeIn();
            },
            success: function( response ){
                response = $.parseJSON(response);

                if( response.order == true ){
                    clearformall($("#order-confirm-form"));
                    $("div#mask").delay(1000).fadeOut(function(){
                        $('#oc_invoice').val(response.invoice);
                        $('#checkout_page').hide();
                        $('#order_confirm_page').fadeIn();
                        $('.bill').show();
                        $('html, body').animate({ scrollTop: $("#fundrising").offset().top}, 500); 
                    });
                }else{
                    $("div#mask").fadeOut();
                    msg.empty().html(response.message).fadeIn('fast').delay(5000).fadeOut('slow');
                }
                
                return false;
            }
        });
    });
    
    // Back To Billing Information
    $('#button-checkout-prev1').click(function (e){
        e.preventDefault();
        $('#shipping_info').hide(function(){
            cos_namaInfo.hide();
            cos_propinsiInfo.hide();
            cos_kotaInfo.hide();
            cos_alamatInfo.hide();
            cos_kodeposInfo.hide();
            cos_phoneInfo.hide();
        });
        $("div#mask").fadeIn().delay(1000).fadeOut(function(){
            $('#billing_info').fadeIn();
            $('html, body').animate({ scrollTop: $("#fundrising").offset().top}, 500); 
        });
    });
    
    // Bact To Shipping Information
    $('#button-checkout-prev2').click(function (e){
        e.preventDefault();
        $('#payment_info').hide();
        $("div#mask").fadeIn().delay(1000).fadeOut(function(){
            var ship_val = $('input[name=co_ship]:checked').val();
            
            if( ship_val == "ship_this" ){
                $('#billing_info').fadeIn();
            }else{
                $('#shipping_info').fadeIn();
            }

            $('html, body').animate({ scrollTop: $("#fundrising").offset().top}, 500);
        });
    });
    
    // Bact To Payment Information
    $('#button-checkout-prev3').click(function (e){
        e.preventDefault();
        $('#order_review').hide();
        $("div#mask").fadeIn().delay(1000).fadeOut(function(){
            $('#payment_info').fadeIn();
            $('html, body').animate({ scrollTop: $("#fundrising").offset().top}, 500);
        });
    });
    
    $("input#co_cityto").typeahead({
        onSelect: function(item) {
            if( item.value != "" || item.value > 0 ){
                count_tarif(item.value);
            }
        },
        ajax: {
            url: $("input#co_cityto").data('url'),
            timeout: 500,
            triggerLength: 1,
            method: "post",
            preDispatch: function (query) {
                $("div#mask").fadeIn();
                return {
                    search: query
                }
            },
            preProcess: function (data) {
                $("div#mask").fadeOut();
                var el  = $('#co_paket');
                
                // Hide the list, there was some error
                $(el).hide().empty();
                $(el).html('<option value="">Pilih Paket Pengiriman</option>').fadeIn('fast');
                
                if (data.success === false) {
                    return false;
                }else{
                    return data.tarif;
                }
            }
        },
        items:10,
        scrollBar: true,
    }).blur(function(){
        var el  = $('#co_paket');
        if( $(this).val() == '' ) {
            // Hide the list, there was some error
            $(el).hide().empty();
            $(el).html('<option value="">Pilih Paket Pengiriman</option>').fadeIn('fast');
        }
    }).keyup(function(){
        var el  = $('#co_paket');
        if( $(this).val() == '' ) {
            // Hide the list, there was some error
            $(el).hide().empty();
            $(el).html('<option value="">Pilih Paket Pengiriman</option>').fadeIn('fast');
        }
    });
    
    // Count Tarif
    function count_tarif(id){
        var url = window.location.origin + "/fundrising/counttarif";
        var el  = $('#co_paket');
        
        $.ajax({
            type: "POST",
            data: {
                'id' : id,
            },
            url: url,
            success: function( response ){
                response = $.parseJSON(response);
                
                co_paketInfo.empty().fadeOut();
                $(el).hide().empty();
                $(el).html(response.paket).fadeIn('fast');
            }
        });
    }
    
    // Load Cart List Review
    function _load_cartlist_review( url ){
        var url_cart    = typeof(url) != 'undefined' ? url : 'fundrising/cartlistreview';
        var elc         = $("#cart_list_review");
        
        $.ajax({
            type: "POST",
            data: {
                'paket' : $('#co_paket').val(),
            },
            url: url_cart,
            success: function( response ){
                response = $.parseJSON(response);
                
                $(elc).hide().empty();
                $(elc).html(response.items).fadeIn('fast');
                
                // Checkout Button
                $("#btn_checkout").click(function(e){
                    e.preventDefault();
                    $("#shopping_page").hide();
                    $("#checkout_page").fadeIn('fast',function(){
                        $('#shipping_info, #payment_info, #order_review').hide();
                        $('#billing_info').show();
                    });
                });
                
                return false;
            }
        });
    }
    //==================================================================================================//
    
    
    //==================================================================================================//
    //----------------------------------- Order Confirm Validation -------------------------------------//
    //==================================================================================================//
    
    //Form Declaration
    var oc_form             = $("#order-confirm-form");
    
    //Global Vars
    var oc_invoice          = $("#oc_invoice");
    var oc_invoiceInfo      = $("#oc_invoice_info");
    var oc_email            = $("#oc_email");
    var oc_emailInfo        = $("#oc_email_info");
    var oc_amount           = $("#oc_amount");
    var oc_amountInfo       = $("#oc_amount_info");
    var oc_payment          = $("#oc_payment");
    var oc_paymentInfo      = $("#oc_payment_info");
    var oc_bank_from        = $("#oc_bank_from");
    var oc_bank_fromInfo    = $("#oc_bank_from_info");
    var oc_rek_from         = $("#oc_rek_from");
    var oc_rek_fromInfo     = $("#oc_rek_from_info");
    
    // Reset Form On Refresh
    clearformall(oc_form);
    
    oc_invoice.bind('keyup blur', function(){ validateInput(oc_invoice, 'invoice', oc_invoiceInfo) });
    oc_email.bind('keyup blur', function(){ validateEmail(oc_email, oc_emailInfo, 1) });
    oc_amount.bind('keyup blur', function(){ validateInput(oc_amount, 'jumlah', oc_amountInfo) });
    oc_payment.bind('keyup change blur click', function(){ validateInput(oc_payment, 'payment', oc_paymentInfo) });
    oc_bank_from.bind('keyup blur', function(){ validateInput(oc_bank_from, 'bank pengirim', oc_bank_fromInfo) });
    oc_rek_from.bind('keyup blur', function(){ validateInput(oc_rek_from, 'rekening pengirim', oc_rek_fromInfo) });
    
    // On Submitting
    // Billing Information Validation
    $('#button-order-confirm').click(function (e){
        e.preventDefault();
        var url_oc          = window.location.origin + '/fundrising/orderconfirm';
        var msg             = $('#confirm_message');
        
        if( validateInput(oc_invoice, 'invoice', oc_invoiceInfo) & 
            validateEmail(oc_email, oc_emailInfo, 1) &
            validateInput(oc_amount, 'jumlah', oc_amountInfo) & 
            validateInput(oc_payment, 'payment', oc_paymentInfo) & 
            validateInput(oc_bank_from, 'bank pengirim', oc_bank_fromInfo) & 
            validateInput(oc_rek_from, 'rekening pengirim', oc_rek_fromInfo) ){
                
            $.ajax({
                type: "POST",
                data: oc_form.serialize(),
                url: url_oc,
                beforeSend: function (){
                    $("div#mask").fadeIn();
                },
                success: function( response ){
                    response = $.parseJSON(response);
                    $("div#mask").fadeOut();
                                    
                    if( response.confirm == true ){
                        clearformall( $("#order-confirm-form") );
                        $('#order_confirm_page').hide();
                        $('#thanks_order_page').fadeIn();
                        $('html, body').animate({ scrollTop: $("#fundrising").offset().top}, 500); 
                    }else{
                        msg.empty().html(response.message).fadeIn('fast').delay(5000).fadeOut('slow');
                        $('html, body').animate({ scrollTop: $("#fundrising").offset().top}, 500);
                    }
                }
            });
        }
        return false;
    });
    //==================================================================================================//
});
